/**
 * @created June 7, 2004
 *
 * @modified March 8, 2007
 * @author jprieur
 */
package kernel;

public class DataTrajectoryMove extends DataTrajectory 
{
    public static final int TYPEQUARTERCIRCLEHORA = 0;
    public static final int TYPEQUARTERCIRCLETRIGO = 1;
    public static final int TYPESEMICIRCLEHORA = 2;
    public static final int TYPESEMICIRCLETRIGO = 3;
    public static final int TYPELINE = 4;
    public static final int TYPERANDOM = 5;
    private int _type;

    private final String[] TypeName = { "QuarterCircleHorair", 
					"QuarterCircleTrigo",
					"SemiCircleHorair",
					"SemiCircleTrigo",
					"Line", 
					"Random" };
    
    private double _xdest;
    public final static double XDEST_DEF = 0;

    private double _ydest;
    public final static double YDEST_DEF = 0;
    
    private double _speed;
    public final static double SPEED_MIN = 0;
    public final static double SPEED_DEF = 0.05;

    private double _time;	
    public final static double TIME_MIN = 0;
    public final static double TIME_DEF = 0;
	
    private boolean _rSpeed; // is the speed randomized?
    public final static boolean RSPEED_DEF = true;

    /**
     * Generic constructor
     * @param type trajectory type
     * @param xdest destination x-coordinate
     * @param ydest destination y-coordinate
     * @param speed speed, maximum speed when random speed is activated
     * @param rSpeed random speed activation
     */
    public DataTrajectoryMove(int type, 
			      double xdest, 
			      double ydest, 
			      double speed, 
			      boolean rSpeed)
    {
	setType(type);
	setXdest(xdest);
	setYdest(ydest);
	setSpeed(speed);
	setRSpeed(rSpeed);
    }	

    /**
     * Limited random trajectory constructor
     * @param time duration of the movement
     * @param speed speed, maximum speed when random speed is activated
     * @param rSpeed random speed activation
     */
    public DataTrajectoryMove(double time,
			      double speed, 
			      boolean rSpeed){
	setType(TYPERANDOM);
	setTime(time);
	setSpeed(speed);
	setRSpeed(rSpeed);
    }	
    
    /** 
     * Infinite random trajectory constructor
     * @param speed maximum speed
     */
    public DataTrajectoryMove(double speed)
    {
	setType(TYPERANDOM);
	setSpeed(speed);				
	setTime(Integer.MAX_VALUE);				
	setRSpeed(true);	
    }	
    
    /**
     * Constructor which inits fields with default values
     */
    public DataTrajectoryMove()
    {
	setType(TYPERANDOM);
	setTime(TIME_DEF);
	setSpeed(SPEED_DEF);
	setRSpeed(RSPEED_DEF);
    } 

    public boolean setType(int type)
    {
	_type = type;
	return true;
    }

    public int getType()
    {
	return _type;
    }
    
    public boolean setXdest(double xdest)
    {
	_xdest = xdest;
	return true;
    }

    public double getXdest()
    {
	return _xdest;
    }

    public boolean setYdest(double ydest)
    {
	_ydest = ydest;
	return true;
    }
    
    public double getYdest()
    {
	return _ydest;
    }

    public boolean setSpeed(double speed)
    {
	boolean done = false;
	if(checkBounds(UNDEFINED, SPEED_MIN, speed)){
	   	    _speed = SPEED_DEF;
	}else{
 		_speed = speed;
	    done = true;

	}
	return done;
    }

    public double getSpeed()
    {
	return _speed;
    }

    public boolean setTime(double time)
    {
	boolean done = false;
	if(checkBounds(UNDEFINED, TIME_MIN, time)){
		    _time = TIME_DEF;
	}else{
    	_time = time;
	    done = true;
	}
	return done;
    }
    
    public double getTime()
    {
	return _time;
    }

    public boolean setRSpeed(boolean rSpeed)
    {
	_rSpeed = rSpeed;
	return true;
    }

    public boolean getRSpeed()
    {
	return _rSpeed;
    }

    public String toString(){
	return "Movement : type=" + TypeName[_type] + (_type == TYPERANDOM ? " ; length:" + _time/1000 : " ;xdest:" + _xdest + ";ydest=" + _ydest) + (_rSpeed ? ";Random Speed (max :" + _speed*1000 + "m/s)\n" : ";Speed:" + _speed*1000 + "m/s\n");
    }

}


